<template>
	<view class="page">
		<view class="page-body">
			<!-- 页面主体内容开始 -->
			<vk-data-form
				ref="form1"
				v-model="form1.data"
				:rules="form1.props.rules"
				:action="form1.props.action"
				:form-type="form1.props.formType"
				:columns='form1.props.columns'
				:loading.sync="form1.props.loading"
				:labelWidth="form1.props.labelWidth"
				:footer-show="false"
				@success="formSuccess"
			></vk-data-form>
			<!-- 页面主体内容结束 -->
		</view>
		<view class="page-footer">
			<!-- 页面底部内容开始 -->
			<el-button v-if="page.showBack" plain style="margin-right: 20px;width: 80px;" @click="pageBack" :loading="form1.props.loading">{{ page.cancelText }}</el-button>
			<el-button type="primary" style="width: 80px;" @click="submitForm" :loading="form1.props.loading">{{ page.submitText }}</el-button>
			<!-- 页面底部内容开始 -->
		</view>
		<view class="page-dialog">
			<!-- 页面弹窗内容开始 -->

			<!-- 页面弹窗内容开始 -->
		</view>
	</view>
</template>

<script>
	var vk = uni.vk;									// vk实例
	export default {
		props:{
			localdata:{},
			pageList:{}
		},
		data() {
			// 页面数据变量
			return {
				// init请求返回的数据
				data:{

				},
				page: {
					title: "首页轮播图",
					submitText: "设置",
					cancelText: "返回",
					showBack: false,
					backPage:""
				},
				form1: {
					// 表单请求数据，此处可以设置默认值
					data: {

					},
					// 表单属性
					props: {
						// 表单请求地址
						action: "admin/business/sys.dynamicPages.update",
						// 表单字段显示规则
						columns: [
							{ key: "", title: "参数设置", type: "bar-title" },
							{ key:"show", title:"是否显示", type:"switch", activeValue:true, inactiveValue:false },
							{ key: "", title: "轮播图设置", type: "bar-title" },
							{ key: "data", title: "data", type: "object", showLabel: false,
								columns:[
									{ key: "col", title: "每行显示几个", type: "number", width:200, rightText:"个", clearable: false, tips:"建议每行显示3或4个为佳" },
									{ key: "iconSize", title: "图标大小", type: "number", width:200, rightText:"rpx", clearable: false },
									{
										key:"list", title:"", type:"array<object>",
										showAdd:true,
										showClear:false,
										showSort:true,
										// 新增一行时,该行的默认值
										defaultValue:{
											pageType:0,
											image:"",
										},
										rightBtns:['copy','delete'],
										// 每行每个字段对应的渲染规则
										columns:[
											{
												key:"iconType", title:"图标类型", type:"radio", width:180, clearable: false,
												optionType:"button",
												data:[
													{ value:"icon", label:"图标" },
													{ value:"image", label:"图片" }
												]
											},
											{
												key:"image", title:"图片", type:"image", limit:1, width:120, clearable: false,
												showRule:(formData)=>{
													return formData.iconType == "image";
												}
											},
											{
												key:"icon", title:"图标", type:"icon", limit:1, width:100, clearable: false,
												filter:(name)=>{
													// 不显示element图标
													return name.indexOf("el-icon") === 0 ? false : true;
												},
												showRule:(formData)=>{
													return formData.iconType == "icon";
												}
											},
											{ key: "backgroundColor", title: "图标背景色", type: "color", width:100,
												showRule:(formData)=>{
													return formData.iconType == "icon";
												}
											},
											{ key: "color", title: "图标颜色", type: "color", width:100,
												showRule:(formData)=>{
													return formData.iconType == "icon";
												}
											},
											{
												key:"title", title:"按钮标题", type:"text", minWidth:120,
											},
											{
												key:"pagePath", title:"选择已有页面", type:"select", placeholder:"请选择", width:200,
												data:()=>{
													return this.pageList;
												},
												action:"admin/business/sys.pages.getList",
												props:{ list:"rows", value:"url", label:"name" },
												showAll:true,
												watch: ({ value, formData, column, index, $set }) => {
													// 此处演示根据选择的值动态改变text1的值
													$set("page", value);
												}
											},
											{
												key:"page", title:"页面地址", type:"text", minWidth:300,
											}
										]
									}
								]
							},
							{ key: "", title: "高级功能", type: "bar-title" },
							{ key:"showData", title:"是否显示源码", type:"switch", activeValue:true, inactiveValue:false },
							{ key:"data", title:"数据源编辑器", type:"json", showLabel:false, showRule:"showData==true" }
						],
						// 表单验证规则
						rules: {

						},
						labelWidth: "100px"
					}
				}
			}
		},
		created(){
			this.form1.data = this.localdata;
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			vk = this.vk;
			this.options = options;
			this.init(options);
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady(){

		},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {

		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {

		},
		// 函数
		methods: {
			// 页面数据初始化函数
			init(options){

			},
			// 页面跳转
			pageTo(path){
				vk.navigateTo(path);
			},
			// 页面返回
			pageBack(){
				let that = this;
				const pages = getCurrentPages();
				if (pages.length>1 && pages[0].route !== that.$page.route) {
					vk.navigateBack();
				} else if(that.page.backPage) {
					vk.navigateTo(that.page.backPage);
				}
			},
			// 表单重置
			resetForm() {
				this.$refs.form1.resetForm();
			},
			// 表单提交
			submitForm(){
				this.$refs.form1.submitForm();
			},
			// 表单提交成功后的回调
			formSuccess(res){

			}
		},
		// 监听器
		watch:{

		},
		// 计算属性
		computed:{

		}
	}
</script>
<style lang="scss" scoped>

</style>
